package com.atguigu.daijia.driver.controller;

import com.atguigu.daijia.common.login.GuiguLogin;
import com.atguigu.daijia.common.result.Result;
import com.atguigu.daijia.common.util.AuthContextHolder;
import com.atguigu.daijia.driver.client.DriverInfoFeignClient;
import com.atguigu.daijia.driver.service.DriverService;
import com.atguigu.daijia.model.form.driver.DriverFaceModelForm;
import com.atguigu.daijia.model.form.driver.UpdateDriverAuthInfoForm;
import com.atguigu.daijia.model.vo.driver.DriverAuthInfoVo;
import com.atguigu.daijia.model.vo.driver.DriverLoginVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Slf4j
@Tag(name = "司机API接口管理")
@RestController
@RequestMapping(value="/driver")
@SuppressWarnings({"unchecked", "rawtypes"})
public class DriverController {

    @Autowired
    private DriverService driverService;

    @Autowired
    private DriverInfoFeignClient driverInfoFeignClient;


    /*
     * 登录接口
     * */
    @Operation(summary = "小程序登录")
    @GetMapping("/login/{code}")
    public Result<String> wxLogin(@PathVariable String code){
        return Result.ok(driverService.login(code));
    }

    /*
    * 获取司机信息
    * */
    @Operation(summary = "获取司机信息")
    @GetMapping("/getDriverLoginInfo")
    @GuiguLogin
    public Result<DriverLoginVo> getDriverLoginInfo(){
        //获取用户id
        Long driverId = AuthContextHolder.getUserId();
        //远程调用获取司机信息
        DriverLoginVo driverLoginVo = driverInfoFeignClient.getDriverInfo(driverId).getData();
        return Result.ok(driverLoginVo);
    }

    /*
    * 司机认证信息回显
    * */
    @Operation(summary = "获取司机认证信息")
    @GuiguLogin
    @GetMapping("/getDriverAuthInfo")
    public Result<DriverAuthInfoVo> getDriverAuthInfo(){
        Long driverId = AuthContextHolder.getUserId();
        return Result.ok(driverService.getDriverAuthInfo(driverId));
    }

    /*
    * 更新司机认证信息
    * */
    @Operation(summary = "更新司机认证信息")
    @GuiguLogin
    @PostMapping("/updateDriverAuthInfo")
    public Result<Boolean> updateDriverAuthInfo(@RequestBody UpdateDriverAuthInfoForm updateDriverAuthInfoForm){
        updateDriverAuthInfoForm.setDriverId(AuthContextHolder.getUserId());
        return Result.ok(driverService.updateDriverAuthInfo(updateDriverAuthInfoForm));
    }

    /*
    * 创建司机人脸识别模型
    * */
    @Operation(summary = "创建司机人脸模型")
    @GuiguLogin
    @PostMapping("/creatDriverFaceModel")
    public Result<Boolean> creatDriverFaceModel(@RequestBody DriverFaceModelForm driverFaceModelForm){
        driverFaceModelForm.setDriverId(AuthContextHolder.getUserId());
        return Result.ok(driverService.creatDriverFaceModel(driverFaceModelForm));
    }

    /*
    * 判断司机当日是否进行过人脸识别
    * */
    @Operation(summary = "判断司机当日是否进行过人脸识别")
    @GuiguLogin
    @GetMapping("/isFaceRecognition")
    Result<Boolean> isFaceRecognition(){
        Long driverId = AuthContextHolder.getUserId();
        return Result.ok(driverService.isFaceRecognition(driverId));
    }

    /*
    * 人脸识别认证
    * */
    @Operation(summary = "人脸识别认证")
    @GuiguLogin
    @PostMapping("verifyDriverFace")
    public Result<Boolean> verifyDriverFace(@RequestBody DriverFaceModelForm driverFaceModelForm){
        driverFaceModelForm.setDriverId(AuthContextHolder.getUserId());
        return Result.ok(driverService.verifyDriverFace(driverFaceModelForm));
    }

    /*
    * 开启接单服务
    * */
    @Operation(summary = "开启接单服务")
    @GuiguLogin
    @GetMapping("/startService")
    public Result<Boolean> startService(){
        Long driverId = AuthContextHolder.getUserId();
        return Result.ok(driverService.startService(driverId));
    }

    /*
     * 停止接单服务
     * */
    @Operation(summary = "停止接单服务")
    @GuiguLogin
    @GetMapping("/stopService")
    public Result<Boolean> stopService(){
        Long driverId = AuthContextHolder.getUserId();
        return Result.ok(driverService.stopService(driverId));
    }

}

